unit edtcontractor;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, 
  Buttons, ExtCtrls, ComCtrls, RzTreeVw, Mask, RzEdit, RzLstBox, RzButton,
  Strutils;

type
  Tedtcontractorfrm = class(TForm)
    RzEdit1: TRzEdit;
    Label1: TLabel;
    RzEdit2: TRzEdit;
    Label2: TLabel;
    RzEdit3: TRzEdit;
    Label3: TLabel;
    RzEdit4: TRzEdit;
    Label4: TLabel;
    lstctrctorpicker: TRzListBox;
    Label5: TLabel;
    RzBitBtn1: TRzBitBtn;
    RzBitBtn2: TRzBitBtn;
    lstpicker: TRzListBox;
    RzBitBtn3: TRzBitBtn;
    RzBitBtn4: TRzBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure RzBitBtn1Click(Sender: TObject);
    procedure RzBitBtn2Click(Sender: TObject);
    procedure RzBitBtn3Click(Sender: TObject);
    procedure RzBitBtn4Click(Sender: TObject);
    procedure RzEdit2KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  edtcontractorfrm: Tedtcontractorfrm;

implementation

{$R *.dfm}

uses
  includefile, dbmodule, editpicker;

procedure Tedtcontractorfrm.FormCreate(Sender: TObject);
var
  I:integer;
begin
  Caption:=GetCaption('edtcontractorfrm',1000);
  for I:=0 to ComponentCount-1 do begin
    if Components[I] is TLabel then begin
      if 0<>TLabel(Components[I]).Tag then
        TLabel(Components[I]).Caption:=
                GetCaption('edtcontractorfrm',TLabel(Components[I]).Tag);
    end;
    if Components[I] is TRzBitbtn then begin
      if 0<>TRzBitbtn(Components[I]).Tag then
        TRzBitbtn(Components[I]).Caption:=
                GetCaption('edtcontractorfrm',TRzBitbtn(Components[I]).Tag);
    end;
  end;
  RzBitbtn3.Hint:=GetCaption('Hints',103);
  RzBitbtn4.Hint:=GetCaption('Hints',104);
  dbmodulefrm.getRFIDName(lstpicker.Items);
end;

procedure Tedtcontractorfrm.RzBitBtn1Click(Sender: TObject);
begin
  modalresult:=mrOk;
end;

procedure Tedtcontractorfrm.RzBitBtn2Click(Sender: TObject);
begin
  modalresult:=mrCancel;
end;

procedure Tedtcontractorfrm.RzBitBtn3Click(Sender: TObject);
var
  i:integer;
begin
  for i:=0 to  lstpicker.Count-1 do begin
    if lstpicker.Selected[i] then begin
      if not lstctrctorpicker.FindItem(lstpicker.Items.Strings[i]) then
      lstctrctorpicker.Items.Add(lstpicker.Items.Strings[i]);
    end;
  end;
end;

procedure Tedtcontractorfrm.RzBitBtn4Click(Sender: TObject);
var
  rfid:String;
  tmpPicker:TPicker;
  //index:integer;
begin
  rfid:=lstctrctorpicker.SelectedItem;
  //Trim(LeftStr(comboRFID.Text,10));
  //index:=comboRFID.ItemIndex;
  With Teditpickerfrm.Create(Application) do begin
    Caption:=GetCaption('editpickerfrm',999);
    tmpPicker:=dbModulefrm.getPicker(rfid);
    txtRFID.Text:=rfid;
    txtName.Text:=tmpPicker.name;
    dtpbthday.DateTime:=tmpPicker.birthday;
    txtLKMan.Text:=tmpPicker.ID_DOC;
    txtLKManTEL.Text:=tmpPicker.MOB_TEL;
    txtTFN.Text:=tmpPicker.TFN;
    txtaddress.Text:=tmpPicker.address;
    txtEmail.Text:=tmpPicker.Email;
    txtHM_TEL.Text:=tmpPicker.HM_TEL;
    txtExt.Text:=tmpPicker.Ext;

    if Trim(tmpPicker.sex)='FEMALE' then
      cmbxSex.ItemIndex:=1
    else
      cmbxSex.ItemIndex:=0;

    case tmpPicker.TFNtype of
      0:cmbxTFNTYPE.ItemIndex:=0;
      1:cmbxTFNTYPE.ItemIndex:=1;
      else cmbxTFNTYPE.ItemIndex:=2;
    end;
    //cmbxcontractor.Text:=dbmodulefrm.getConstractorNameByID(tmpPicker.contractor);
    if MroK=showmodal then begin
      dbmodulefrm.dbquery.Active:=False;
      dbmodulefrm.dbquery.SQL.Clear;
      dbmodulefrm.dbquery.SQL.Add('Update employee ');
      dbmodulefrm.dbquery.sql.Add(Format('SET RFID=''%s'', [NAME]=''%s'', SEX=''%s'', BIRTHDAY=#%s#,',
                [RightStr('0000000000'+txtRFID.Text,10),txtNAME.text,cmbxSex.Text,FormatDateTime('yyyy-MM-dd',dtpBthday.Date)]));
      dbmodulefrm.dbquery.sql.Add(Format('TFN=''%s'', TFNTYPE=%d, CONTRACTORNAME=%d, ID_DOC=''%s'',',
                                          [txtTFN.text,cmbxTfntype.itemindex,strtoint(Trim(LeftStr(cmbxcontractor.text,4))),txtLKman.text]));
      dbmodulefrm.dbquery.sql.Add(Format('MOB_TEL=''%s'', ADDRESS=''%s'', EMAIL=''%s'',EXT=''%s'',HM_TEL=''%s''',
                                          [txtLkmantel.text,txtaddress.text,txtemail.text,txtext.text,txthm_tel.text]));
      dbmodulefrm.dbquery.sql.Add(Format('Where Right(RFID,%d)=''%s''',[RFIDLEN,RFID]));
      dbmodulefrm.dbquery.ExecSQL;
    end;
  end;
  //dbmodulefrm.getRFIDName(comboRFID.Items);
  //comboRFID.Items.Insert(0,'All');
  //comboRFID.ItemIndex:=index;
  lstctrctorpicker.DeleteSelectedItems;
end;

procedure Tedtcontractorfrm.RzEdit2KeyPress(Sender: TObject;
  var Key: Char);
begin
  case key of
    '0'..'9',#$08,#$0D:begin  end;
    else begin
      key:=#00;
      Application.MessageBox(pchar(GetCaption('MsgBox',107)),
                             pchar(GetCaption('MsgBox',106)),MB_ICONINFORMATION);
    end;
  end;
end;

end.
